#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <stdbool.h>

//https://leetcode.cn/problems/linked-list-cycle-ii/submissions/

struct ListNode {
    int val;
    struct ListNode *next;
};

struct ListNode* detectCycle(struct ListNode* head){
    if (head == NULL || head->next == NULL) {
        return NULL;
    }
    struct ListNode *fast = head;
    struct ListNode *slow = head;
    struct ListNode *curr = head;
    do {
        if (fast == NULL || fast->next == NULL) {
            return NULL;
        }
        slow = slow->next;
        fast = fast->next->next;
    } while (slow != fast);
    while (curr != slow) {
        slow = slow->next;
        curr = curr->next;
    }
    return curr;
}


int main() {

    return 0;
}